<?php
include("./include/config.inc.php");

if(isset($_POST['submitBtn']))
{
  $firstName         = $_POST['firstName'] && ($_POST['firstName'] != "") ? $_POST['firstName'] : 0 ;
  $middletName       = $_POST['middletName'] && ($_POST['middletName'] != "") ? $_POST['middletName'] : 0 ;
  $lastName          = $_POST['lastName'] && ($_POST['lastName'] != "") ? $_POST['lastName'] : 0 ;
  $birthdate         = $_POST['bdateYear']."-".$_POST['bdateMonth']."-".$_POST['bdateDay'];
  $gender            = $_POST['gender'];
  $height            = $_POST['height'] && ($_POST['height'] != "") ? $_POST['height'] : 0 ;
  $weight            = $_POST['weight'] && ($_POST['weight'] != "") ? $_POST['weight'] : 0 ;
  $email             = $_POST['email'] && ($_POST['email'] != "") ? $_POST['email'] : 0 ;
  $qualification     = $_POST['qualification'] && ($_POST['qualification'] != "") ? $_POST['qualification'] : 0 ;
  $occupation        = $_POST['occupation'] && ($_POST['occupation'] != "") ? $_POST['occupation'] : 0 ;
  $income            = $_POST['income'] && ($_POST['income'] != "") ? $_POST['income'] : 0 ;
  $address           = $_POST['address'] && ($_POST['address'] != "") ? $_POST['address'] : 0 ;
  $mobileNo          = $_POST['mobileNo'] && ($_POST['mobileNo'] != "") ? $_POST['mobileNo'] : 0 ;
  $fathersOccupation = $_POST['fathersOccupation'] && ($_POST['fathersOccupation'] != "") ? $_POST['fathersOccupation'] : 0 ;
  $fathersIncome     = $_POST['fathersIncome'] && ($_POST['fathersIncome'] != "") ? $_POST['fathersIncome'] : 0 ;
  $note              = $_POST['note'] && ($_POST['note'] != "") ? $_POST['note'] : 0 ;
	
  $insertReg = "INSERT INTO shadi(firstName, middleName, lastName, birthdate, gender, height, weight, email, qualification, occupation, monthlyIncome, permanentAddress, mobileNo, fathersOccupation, fatherMonthlyIncome, note)
	                    VALUES('".$firstName."',
	                          '".$middletName."',
	                          '".$lastName."',
	                          '".$birthdate."',
	                          '".$gender."',
	                          '".$height."',
	                          '".$weight."',
	                          '".$email."',
	                          '".$qualification."',
	                          '".$occupation."',
	                          '".$income."',
	                          '".$address."',
	                          '".$mobileNo."',
	                          '".$fathersOccupation."',
	                          '".$fathersIncome."',
	                          '".$note."')";
  $insertRegRes = mysql_query($insertReg);
  if(!$insertRegRes)
  {
  	echo "insert Fail";
  }
  else
  {
    header("Location:shadi.php");
  }
}

$regArray = array();
$j = 0;
$register = "SELECT shadiId, firstName, middleName, lastName, email, birthdate, gender, height, weight, qualification, occupation, monthlyIncome, permanentAddress, mobileNo, fathersOccupation, fatherMonthlyIncome, note 
               FROM shadi";
$registerRes = mysql_query($register);
while($registerRow = mysql_fetch_array($registerRes))
{
  $regArray[$j]['shadiId']             = $registerRow['shadiId'];
  $regArray[$j]['firstName']           = $registerRow['firstName'];
  $regArray[$j]['middleName']          = $registerRow['middleName'];
  $regArray[$j]['lastName']            = $registerRow['lastName'];
  $regArray[$j]['birthdate']           = $registerRow['birthdate'];
  $regArray[$j]['gender']              = $registerRow['gender'];
  $regArray[$j]['height']              = $registerRow['height'];
  $regArray[$j]['weight']              = $registerRow['weight'];
  $regArray[$j]['email']               = $registerRow['email'];
  $regArray[$j]['qualification']       = $registerRow['qualification'];
  $regArray[$j]['occupation']          = $registerRow['occupation'];
  $regArray[$j]['monthlyIncome']       = $registerRow['monthlyIncome'];
  $regArray[$j]['permanentAddress']    = $registerRow['permanentAddress'];
  $regArray[$j]['mobileNo']            = $registerRow['mobileNo'];
  $regArray[$j]['fathersOccupation']   = $registerRow['fathersOccupation'];
  $regArray[$j]['fatherMonthlyIncome'] = $registerRow['fatherMonthlyIncome'];
  $regArray[$j]['note']                = $registerRow['note'];
  $j++;
}
$smarty->assign("regArray",$regArray);
$smarty->display("shadi.tpl");
?>